# -*- coding: utf-8 -*-

import os
from utils.urlrequest import get_db
from db.prepare import get_tx_data_and_output
from db.getdata import get_from_local
from db.prepare2 import mix_train_data_and_output
import numpy as np
import pandas as pd

cdir = os.path.dirname(__file__)  # 当前路径
meta_file = os.path.join(cdir, 'data', 'meta.csv')
data_file = os.path.join(cdir, 'data', 'cluster.csv')
cluster_rsl = os.path.join(cdir, 'data', 'clustr_rsl.csv')


def test_utils_get_db():
    """测试utils.urlequest.get_db函数
    
    get_db 函数从指定的网路URI中下载相关数据库，数据库格式为csv文本
    简单示例如下:
    >> get_db(data_file_uri)

    详细调用，请参考函数说明
    """
    
    get_db('https://gitee.com/moonkie/data_base/raw/master/output.csv')


def test_get_local_data():
    """测试db.getdata.get_from_local函数

    get_from_local 函数从给定路径参数加载数据库文件，并返回一个io.Bytes
    """
    get_from_local(meta_file)


def test_get_tx_data():
    """测试db.prepare.get_tx_data_and_output函数
    """

    get_tx_data_and_output(meta_file)


def test_cluster():
    from model.cluster import train
    from db.prepare import get_tx_data
    test_get_tx_data()
    data = pd.read_csv(data_file)
    rsl = train(data, issave=True)
    rsl.to_csv('rsl.csv', index=None)


def svm_prepare_data():
    mix_train_data_and_output(meta_file, cluster_rsl)
    
if __name__=='__main__':
    # test_utils_get_db()
    # test_get_local_data()
    # test_get_tx_data()
    # test_cluster()
    svm_prepare_data()

    # tmp = 0 and 9 or 10
    # print(tmp)
